package com.wwwc.admin.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.SQLException;

import com.wwwc.admin.web.database.*;
import com.wwwc.util.web.*;

public class TopBarServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
	
	try {
	    response.setContentType("text/html");

	    String user_ip       = request.getRemoteAddr();
	    HttpSession session  = request.getSession(true);
	    PrintWriter out      = response.getWriter();

	    ResourceBundle SystemInfo = (ResourceBundle)session.getAttribute("SystemInfo");
	
	    if (SystemInfo == null) {
		Locale locale = request.getLocale();
		SystemInfo = ResourceBundle.getBundle("SystemInfo", locale); 
		session.setAttribute("SystemInfo", SystemInfo);
	    }
	    
	    String local_ips   = SystemInfo.getString("3wcenter.local_ips");
	    String databases   = SystemInfo.getString("3wcenter.databases");
	    String backup_home = SystemInfo.getString("3wcenter.databases.backup.home");
	    
	    if(user_ip==null || !user_ip.startsWith(local_ips) || databases == null || databases.length()<1) {
		System.out.println("adminDatabseManager:Error:From:"+user_ip);
		return;
	    }

	    String action     = request.getParameter("action");
	    String database   = request.getParameter("database");	

	    String query      = null;
	    
	    if(!user_ip.startsWith(local_ips)) {
		return;
	    }

	    String call_path = request.getContextPath()+request.getServletPath();
	    String id = (String)session.getAttribute("id");
	    String tid = request.getParameter("tid");

	    if(id != null && id.equals("1")) {
		try {
		    RequestDispatcher rd = request.getRequestDispatcher("adminDatabaseManager?who=t");
		    rd.include(request,response);
		}
		catch (Exception e) {
		}
	    }
	    if(id != null && id.equals("2")) {
		try {
		    RequestDispatcher rd = request.getRequestDispatcher("adminUserAccountManager?who=t");
		    rd.include(request,response);
		}
		catch (Exception e) {
		}
	    }
	}
	catch (Exception e) {
	    System.out.println("TopBarServlet:Exception:"+e);
	}
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws IOException, ServletException 
    {
	doPost(request, response);
    }
}








